define(["ajaxBase", "modelNormal"], function (ajaxBase, modelNormal) {
    /*单个分享的内容底部点赞，评论，分享节点*/
    let shareFunction = function (data) {
        this.pointNode = document.createElement("div")
        this.pareShareId = null
        this.pareUserId = null
        this.direction = false
        this.pointNode.className = "share-function"
        if (data) { //没点赞
            this.pointNode.innerHTML =
                this.setPraiseStyle(data) +
                '<a class="add-share"><i class="fa fa-share-alt"></i><span> </span></a>' +
                '<a class="add-comment"><i class="fa fa-comments-o" title="点击查看评论"></i><span> ' + data.totalComment + '</span></a>' +
                '<div class="share-header-bottom"></div>'
        } else {  //有点赞
        }
        this.setPraise()
    }

    //设置praise样式
    shareFunction.prototype.setPraiseStyle = function (data) {
        if (data.hasPraise) {
            return '<a class="add-Pointer"><i class="fa fa-heart"></i><span> ' + data.totalPraise + '</span></a>'; //实心
        } else {
            return '<a class="add-Pointer"><i class="fa fa-heart-o"></i><span> ' + data.totalPraise + '</span></a>'//空心
        }
    };
    shareFunction.prototype.setID = function (shareId, userId) {
        this.pareShareId = shareId;
        this.pareUserId = userId;
    };
    //点赞方法
    shareFunction.prototype.setPraise = function () {
        let that = this;
        this.pointNode.querySelector(".add-Pointer").onclick = function () {
            let i = this.querySelector("i"),
                span = this.querySelector("span");
            if (i.className === "fa fa-heart-o") {
                that.direction = true;
                that.ajax_praise();
            } else if (this.querySelector("i").className === "fa fa-heart") {
                that.direction = false;
                that.ajax_praise();
            }
        };
    };
    shareFunction.prototype.praiseResult = function () {
        let i = this.pointNode.querySelector(".add-Pointer").querySelector("i"),
            span = this.pointNode.querySelector(".add-Pointer").querySelector("span");
        if (i.className === "fa fa-heart-o") {
            i.className = "fa fa-heart";
            let num = span.innerText;
            num = parseInt(num) + 1;
            span.innerText = " " + num;
        } else {
            i.className = "fa fa-heart-o";
            let num = span.innerText;
            num = parseInt(num) - 1;
            span.innerText = " " + num;
        }
    };
    shareFunction.prototype.ajax_praise = function () {
        let url = "/share/praise",
            data = {
                shareId: this.pareShareId,
                userId: 1,
                direction: this.direction
            },
            method = "POST",
            that = this;
        ajaxBase(data, url, method, "Json").then(function (data) {
            that.praiseResult();
        })
    };
    shareFunction.prototype.transmitShare = function () {
        let modelN = new modelNormal();
        this.pointNode.querySelector(".add-share").onclick = function () {
            modelN.setText("转发", "你的感受～");
            modelN.setDisplay("转发");
        };
    };
    return shareFunction
})